package com.yuexin.project.statistic.mealCount.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuexin.common.utils.poi.ExcelUtil;
import com.yuexin.common.utils.security.ShiroUtils;
import com.yuexin.framework.aspectj.lang.annotation.Log;
import com.yuexin.framework.aspectj.lang.enums.BusinessType;
import com.yuexin.framework.web.controller.BaseController;
import com.yuexin.framework.web.domain.AjaxResult;
import com.yuexin.framework.web.page.TableDataInfo;
import com.yuexin.project.statistic.mealCount.domain.MealCount;
import com.yuexin.project.statistic.mealCount.service.IMealCountService;

/**
 * 人员报餐统计 信息操作处理
 * 
 * @author yuexin
 * @date 2018-10-17
 */
@Controller
@RequestMapping("/statistic/mealCount")
public class MealCountController extends BaseController
{
    private String prefix = "statistic/mealCount";
	
	@Autowired
	private IMealCountService mealCountService;
	
	@RequiresPermissions("statistic:mealCount:view")
	@GetMapping()
	public String mealCount()
	{
	    return prefix + "/mealCount";
	}
	
	/**
	 * 查询人员报餐统计列表
	 */
	@RequiresPermissions("statistic:mealCount:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MealCount mealCount)
	{
		startPage();
		mealCount.setCompanyId(ShiroUtils.getCompanyId());
        List<MealCount> list = mealCountService.selectMealCountList(mealCount);
		return getDataTable(list);
	}
	
	/**
	 * 新增人员报餐统计
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存人员报餐统计
	 */
	@RequiresPermissions("statistic:mealCount:add")
	@Log(title = "人员报餐统计", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MealCount mealCount)
	{		
		return toAjax(mealCountService.insertMealCount(mealCount));
	}

	/**
	 * 修改人员报餐统计
	 */
	@GetMapping("/edit/{countId}")
	public String edit(@PathVariable("countId") Integer countId, ModelMap mmap)
	{
		MealCount mealCount = mealCountService.selectMealCountById(countId);
		mmap.put("mealCount", mealCount);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存人员报餐统计
	 */
	@RequiresPermissions("statistic:mealCount:edit")
	@Log(title = "人员报餐统计", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MealCount mealCount)
	{		
		return toAjax(mealCountService.updateMealCount(mealCount));
	}
	
	/**
	 * 删除人员报餐统计
	 */
	@RequiresPermissions("statistic:mealCount:remove")
	@Log(title = "人员报餐统计", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(mealCountService.deleteMealCountByIds(ids));
	}
	
	/**
	 * 导出 exportMealCount
	 */
	@Log(title = "列表", businessType = BusinessType.EXPORT)
    @RequiresPermissions("statistic:mealCount:export")
    @PostMapping("/exportMealCount")
    @ResponseBody
    public AjaxResult export(MealCount mealCount)
    {
		mealCount.setCompanyId(ShiroUtils.getCompanyId());
        List<MealCount> list = mealCountService.selectMealCountList(mealCount);
        ExcelUtil<MealCount> util = new ExcelUtil<MealCount>(MealCount.class);
        return util.exportExcel(list, "人员统计");
    }
}
